package jsgo

import "syscall/js"

type JsObject struct {
	value js.Value
}

func (q *JsObject) available() bool {
	t := q.value.Type()
	return t != js.TypeNull && t != js.TypeUndefined
}

func (q *JsObject) Attr(attrName string) string {
	return MustStr(q.value.Get(attrName))
}

func (q *JsObject) SetAttr(attrName string, attrValue string) {
	q.value.Set(attrValue, attrValue)
}

func (q *JsObject) ToString() string {
	return MustStr(q.value.Call("toString"))
}

func (q *JsObject) ToLocalString() string {
	return MustStr(q.value.Call("toLocaleString"))
}

func (q *JsObject) ValueOf() js.Value {
	return q.value.Call("valueOf")
}

func (q *JsObject) JsValue() js.Value {
	return q.value.JSValue()
}

func (q *JsObject) Call(method string, args ...interface{}) js.Value {
	return q.value.Call(method, args...)
}
